package clientproject;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

import serverproject.model.Account;

import clientproject.window.ClientWindow;

public class Client
{
	public Client(Account account)
	{
		ClientWindow clientWindow = new ClientWindow();

		// TODO IP연결
		try
		{
			Socket socket = new Socket("127.0.0.1", 9002);

			ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
			ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
			oos.writeObject(account);
			Object object = ois.readObject();
			if(object instanceof Account)
			{
				account = (Account) object;
				System.out.println(account.getName());
				Thread senderThread = new SenderThread(socket, account, clientWindow);
				Thread receiverThread = new ReceiverThread(socket, clientWindow);
				senderThread.start();
				receiverThread.start();
			}
			else
				return;

		} catch (Exception e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
